from selenium import webdriver
# 规避被检测
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

import time

option = ChromeOptions()
# # 可防止selenium被检测到合并了
# # ----------------------------------------------------
option.add_experimental_option('excludeSwitches', ['enable-automation'])
# "--headless"不跳出浏览器
# option.add_argument('--headless')
option.add_argument('--disable-gpu')
# #----------------------------------------------------
# #如何让selenium规避掉可检测到的风险
chrome = webdriver.Chrome(options=option)
chrome.get("https://www.baidu.com")
search_box = chrome.find_element(By.ID, "kw")
# 向搜索框输入文本
search_box.send_keys("Selenium WebDriver")
search_box.send_keys(Keys.RETURN)
time.sleep(200)
